/*
 * Copyright (c) 2021.版权所有高金磊
 */

package 领扣算法.A简单题.合并两个有序数组;

import java.util.LinkedList;

public class Main {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        //对num1使用缓冲
        LinkedList<Integer> data=new LinkedList<>();
        int j=0;
        for (int i = 0; i < m+n; i++) {
            data.addLast(i>=m?Integer.MAX_VALUE:nums1[i]);
            if (j>=n){
                nums1[i]=data.pollFirst();
                continue;
            }
            if (data.peekFirst()>nums2[j]){
                nums1[i]=nums2[j++];
            }
            else nums1[i]=data.pollFirst();
        }
    }
    public static void main(String arg[]){//main--来自高金磊
    
        new Main().merge(new int[]{1,2,3,0,0,0}, 3,new int[]{2,5,6} ,3);
    }
}
